package com.yanxi.controller;


import com.yanxi.anno.Log;
import com.yanxi.pojo.Emp;
import com.yanxi.pojo.EmpQueryParam;
import com.yanxi.pojo.PageResult;
import com.yanxi.pojo.Result;
import com.yanxi.service.EmpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RequestMapping("/emps")
@RestController
public class EmpController {
    public static final Logger log = LoggerFactory.getLogger(EmpController.class);

    @Autowired
    private EmpService empService;
    //分页查询
    @GetMapping
    public Result page(EmpQueryParam empQueryParam){
        log.info("分页查询，参数：{} ",empQueryParam);
        PageResult<Emp> pageResult =  empService.page(empQueryParam);
        return Result.success(pageResult);
    }

    @Log
    //新增员工
    @PostMapping
    public Result save(@RequestBody Emp emp){
        log.info("新增员工，员工信息：{}",emp);
        empService.save(emp);
       return Result.success();
    }

    @Log
    //批量删除
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
      log.info("批量删除，id：{}", ids);
      empService.delete(ids);
      return Result.success();
    }



    //修改员工
    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id){
        log.info("查询员工，id：{}", id);
        Emp emp = empService.get(id);
        return Result.success(emp);
    }

    @Log
    @PutMapping
    public Result update(@RequestBody Emp emp){
        log.info("修改员工，员工信息：{}", emp);
        empService.update(emp);
        return Result.success();
    }

    //查询员工-clazz的班主任
    @GetMapping("/list")
    public Result listAll(){
        log.info("查询员工-clazz的班主任");
        List<Emp> list = empService.listAll();
        return Result.success(list);
    }

}
